{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "lesbian-springer",
   "metadata": {},
   "source": [
    "## Seldon V2 Pipeline Errors\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0f2ab2a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "apiVersion: mlops.seldon.io/v1alpha1\n",
      "kind: Model\n",
      "metadata:\n",
      "  name: tfsimple1\n",
      "spec:\n",
      "  storageUri: \"gs://seldon-models/triton/simple\"\n",
      "  requirements:\n",
      "  - tensorflow\n",
      "  memory: 100Ki\n",
      "apiVersion: mlops.seldon.io/v1alpha1\n",
      "kind: Model\n",
      "metadata:\n",
      "  name: tfsimple2\n",
      "spec:\n",
      "  storageUri: \"gs://seldon-models/triton/simple\"\n",
      "  requirements:\n",
      "  - tensorflow\n",
      "  memory: 100Ki\n"
     ]
    }
   ],
   "source": [
    "!cat ./models/tfsimple1.yaml\n",
    "!cat ./models/tfsimple2.yaml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f9e073d7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n",
      "{}\n"
     ]
    }
   ],
   "source": [
    "!seldon model load -f ./models/tfsimple1.yaml \n",
    "!seldon model load -f ./models/tfsimple2.yaml "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "997b4028",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n",
      "{}\n"
     ]
    }
   ],
   "source": [
    "!seldon model status tfsimple1 -w ModelAvailable | jq -M .\n",
    "!seldon model status tfsimple2 -w ModelAvailable | jq -M ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3d017ede",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "apiVersion: mlops.seldon.io/v1alpha1\r\n",
      "kind: Pipeline\r\n",
      "metadata:\r\n",
      "  name: tfsimples\r\n",
      "spec:\r\n",
      "  steps:\r\n",
      "    - name: tfsimple1\r\n",
      "    - name: tfsimple2\r\n",
      "      inputs:\r\n",
      "      - tfsimple1\r\n",
      "      tensorMap:\r\n",
      "        tfsimple1.outputs.OUTPUT0: INPUT0\r\n",
      "        tfsimple1.outputs.OUTPUT1: INPUT1\r\n",
      "  output:\r\n",
      "    steps:\r\n",
      "    - tfsimple2\r\n"
     ]
    }
   ],
   "source": [
    "!cat ./pipelines/tfsimples.yaml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "following-winning",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon pipeline load -f ./pipelines/tfsimples.yaml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "artistic-kentucky",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"pipelineName\": \"tfsimples\",\r\n",
      "  \"versions\": [\r\n",
      "    {\r\n",
      "      \"pipeline\": {\r\n",
      "        \"name\": \"tfsimples\",\r\n",
      "        \"uid\": \"cg5fn9s6dpcs73c4qheg\",\r\n",
      "        \"version\": 1,\r\n",
      "        \"steps\": [\r\n",
      "          {\r\n",
      "            \"name\": \"tfsimple1\"\r\n",
      "          },\r\n",
      "          {\r\n",
      "            \"name\": \"tfsimple2\",\r\n",
      "            \"inputs\": [\r\n",
      "              \"tfsimple1.outputs\"\r\n",
      "            ],\r\n",
      "            \"tensorMap\": {\r\n",
      "              \"tfsimple1.outputs.OUTPUT0\": \"INPUT0\",\r\n",
      "              \"tfsimple1.outputs.OUTPUT1\": \"INPUT1\"\r\n",
      "            }\r\n",
      "          }\r\n",
      "        ],\r\n",
      "        \"output\": {\r\n",
      "          \"steps\": [\r\n",
      "            \"tfsimple2.outputs\"\r\n",
      "          ]\r\n",
      "        },\r\n",
      "        \"kubernetesMeta\": {}\r\n",
      "      },\r\n",
      "      \"state\": {\r\n",
      "        \"pipelineVersion\": 1,\r\n",
      "        \"status\": \"PipelineReady\",\r\n",
      "        \"reason\": \"created pipeline\",\r\n",
      "        \"lastChangeTimestamp\": \"2023-03-10T09:43:03.270822655Z\",\r\n",
      "        \"modelsReady\": true\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon pipeline status tfsimples -w PipelineReady | jq -M ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "87f10a5c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "\t\"model_name\": \"\",\r\n",
      "\t\"outputs\": [\r\n",
      "\t\t{\r\n",
      "\t\t\t\"data\": [\r\n",
      "\t\t\t\t2,\r\n",
      "\t\t\t\t4,\r\n",
      "\t\t\t\t6,\r\n",
      "\t\t\t\t8,\r\n",
      "\t\t\t\t10,\r\n",
      "\t\t\t\t12,\r\n",
      "\t\t\t\t14,\r\n",
      "\t\t\t\t16,\r\n",
      "\t\t\t\t18,\r\n",
      "\t\t\t\t20,\r\n",
      "\t\t\t\t22,\r\n",
      "\t\t\t\t24,\r\n",
      "\t\t\t\t26,\r\n",
      "\t\t\t\t28,\r\n",
      "\t\t\t\t30,\r\n",
      "\t\t\t\t32\r\n",
      "\t\t\t],\r\n",
      "\t\t\t\"name\": \"OUTPUT0\",\r\n",
      "\t\t\t\"shape\": [\r\n",
      "\t\t\t\t1,\r\n",
      "\t\t\t\t16\r\n",
      "\t\t\t],\r\n",
      "\t\t\t\"datatype\": \"INT32\"\r\n",
      "\t\t},\r\n",
      "\t\t{\r\n",
      "\t\t\t\"data\": [\r\n",
      "\t\t\t\t2,\r\n",
      "\t\t\t\t4,\r\n",
      "\t\t\t\t6,\r\n",
      "\t\t\t\t8,\r\n",
      "\t\t\t\t10,\r\n",
      "\t\t\t\t12,\r\n",
      "\t\t\t\t14,\r\n",
      "\t\t\t\t16,\r\n",
      "\t\t\t\t18,\r\n",
      "\t\t\t\t20,\r\n",
      "\t\t\t\t22,\r\n",
      "\t\t\t\t24,\r\n",
      "\t\t\t\t26,\r\n",
      "\t\t\t\t28,\r\n",
      "\t\t\t\t30,\r\n",
      "\t\t\t\t32\r\n",
      "\t\t\t],\r\n",
      "\t\t\t\"name\": \"OUTPUT1\",\r\n",
      "\t\t\t\"shape\": [\r\n",
      "\t\t\t\t1,\r\n",
      "\t\t\t\t16\r\n",
      "\t\t\t],\r\n",
      "\t\t\t\"datatype\": \"INT32\"\r\n",
      "\t\t}\r\n",
      "\t]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon pipeline infer tfsimples \\\n",
    "    '{\"inputs\":[{\"name\":\"INPUT0\",\"data\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],\"datatype\":\"INT32\",\"shape\":[1,16]},{\"name\":\"INPUT1\",\"data\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],\"datatype\":\"INT32\",\"shape\":[1,16]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e27d4f8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error: V2 server error: 400 tfsimple1 : rpc error: code = InvalidArgument desc = [request id: <id_unknown>] unexpected shape for input 'INPUT0' for model 'tfsimple1_1'. Expected [-1,16], got [1,20]\r\n"
     ]
    }
   ],
   "source": [
    "!seldon pipeline infer tfsimples \\\n",
    "    '{\"inputs\":[{\"name\":\"INPUT0\",\"data\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],\"datatype\":\"INT32\",\"shape\":[1,20]},{\"name\":\"INPUT1\",\"data\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],\"datatype\":\"INT32\",\"shape\":[1,16]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5c33133e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"outputs\": [\r\n",
      "    {\r\n",
      "      \"name\": \"OUTPUT0\",\r\n",
      "      \"datatype\": \"INT32\",\r\n",
      "      \"shape\": [\r\n",
      "        \"1\",\r\n",
      "        \"16\"\r\n",
      "      ],\r\n",
      "      \"contents\": {\r\n",
      "        \"intContents\": [\r\n",
      "          2,\r\n",
      "          4,\r\n",
      "          6,\r\n",
      "          8,\r\n",
      "          10,\r\n",
      "          12,\r\n",
      "          14,\r\n",
      "          16,\r\n",
      "          18,\r\n",
      "          20,\r\n",
      "          22,\r\n",
      "          24,\r\n",
      "          26,\r\n",
      "          28,\r\n",
      "          30,\r\n",
      "          32\r\n",
      "        ]\r\n",
      "      }\r\n",
      "    },\r\n",
      "    {\r\n",
      "      \"name\": \"OUTPUT1\",\r\n",
      "      \"datatype\": \"INT32\",\r\n",
      "      \"shape\": [\r\n",
      "        \"1\",\r\n",
      "        \"16\"\r\n",
      "      ],\r\n",
      "      \"contents\": {\r\n",
      "        \"intContents\": [\r\n",
      "          2,\r\n",
      "          4,\r\n",
      "          6,\r\n",
      "          8,\r\n",
      "          10,\r\n",
      "          12,\r\n",
      "          14,\r\n",
      "          16,\r\n",
      "          18,\r\n",
      "          20,\r\n",
      "          22,\r\n",
      "          24,\r\n",
      "          26,\r\n",
      "          28,\r\n",
      "          30,\r\n",
      "          32\r\n",
      "        ]\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon pipeline infer tfsimples --inference-mode grpc \\\n",
    "    '{\"model_name\":\"simple\",\"inputs\":[{\"name\":\"INPUT0\",\"contents\":{\"int_contents\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]},\"datatype\":\"INT32\",\"shape\":[1,16]},{\"name\":\"INPUT1\",\"contents\":{\"int_contents\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]},\"datatype\":\"INT32\",\"shape\":[1,16]}]}' | jq -M ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ea07d3f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error: rpc error: code = Unknown desc = tfsimple1 : rpc error: code = InvalidArgument desc = [request id: <id_unknown>] unexpected shape for input 'INPUT0' for model 'tfsimple1_1'. Expected [-1,16], got [1,20]\r\n"
     ]
    }
   ],
   "source": [
    "!seldon pipeline infer tfsimples --inference-mode grpc \\\n",
    "    '{\"model_name\":\"simple\",\"inputs\":[{\"name\":\"INPUT0\",\"contents\":{\"int_contents\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]},\"datatype\":\"INT32\",\"shape\":[1,20]},{\"name\":\"INPUT1\",\"contents\":{\"int_contents\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]},\"datatype\":\"INT32\",\"shape\":[1,16]}]}' "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e017099a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n",
      "{}\n",
      "{}\n"
     ]
    }
   ],
   "source": [
    "!seldon pipeline unload tfsimples\n",
    "!seldon model unload tfsimple1\n",
    "!seldon model unload tfsimple2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "db3dc8f4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
